<template>
  <div class="dashboard-container">
    <div class="dashboard-text">name: {{ name }}</div>
    <!-- 图表容器 -->
    <div ref="lineChart" style="width: 600px; height: 400px"></div>
  </div>
</template>

<script>
import { mapGetters } from 'vuex'
// 1. 按需引入
import * as echarts from 'echarts/core'
import { LineChart } from 'echarts/charts'
import { GridComponent, TitleComponent } from 'echarts/components'
import { CanvasRenderer } from 'echarts/renderers'

// 2. 注册组件
echarts.use([LineChart, GridComponent, TitleComponent, CanvasRenderer])

export default {
  name: 'Dashboard',
  computed: {
    ...mapGetters(['name'])
  },
  // 3. 在mounted中初始化图表
  mounted() {
    // 初始化图表
    const myChart = echarts.init(this.$refs.lineChart)

    // 绘制图表
    myChart.setOption({
      title: {
        text: '折线图示例'
      },
      xAxis: {
        type: 'category',
        data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
      },
      yAxis: {
        type: 'value'
      },
      series: [
        {
          data: [150, 230, 224, 218, 135, 147, 260],
          type: 'line'
        }
      ]
    })
  }
}
</script>
